use log::info;

trait Hello {
    fn hello() -> String {
        info!("hello");
        "hello".to_string()
    }
}

#[test]
fn hello_test() {
    // let _string = Hello::hello();
}


trait Super {
    fn super_method(&self);
}

trait Sub: Super {
    fn sub_method(&self);
}

// 为所有实现了Sub的类型实现Super
impl<T: Sub> Super for T {
    fn super_method(&self) {
        // 默认实现，或者调用Sub的方法
        self.sub_method(); // 例如，这里我们调用sub_method，但实际中可能不是这样
    }
}

struct MyType;

impl Sub for MyType {
    fn sub_method(&self) {
        info!("MyType::sub_method");
    }
}

#[test]
fn main() {
    let my_type = MyType;
    let sub_ref: &dyn Sub = &my_type;
    let super_ref: &dyn Super = sub_ref; // 这里发生了向上转换
    super_ref.super_method();
}

#[test]
fn test2() {
    let my_type = MyType;
    let super_ref: &dyn Super = &my_type; // 这里发生了向上转换
    super_ref.super_method();
}